//
//  LXStoreViewController.m
//  LvXi_newVersion
//
//  Created by 诸葛孔明 on 16/9/7.
//  Copyright © 2016年 SJT. All rights reserved.
//............................................................................................//
//...........................................首页-侧滑-收藏...........................................//
//............................................................................................//

#import "LXStoreViewController.h"

#import "LXStoreViewCell.h"

static NSString *const LXStoreViewCellID = @"LXStoreViewCell";

@interface LXStoreViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic,weak) UITableView *tableView;

@property(nonatomic,strong)NSArray * focusArray;

@end

@implementation LXStoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.focusArray = [NSArray array];
    [self setUpTableView];
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setUpNavi];
    [[LXDataManager manager] listFocusProductWithComplete:^(BOOL success, id res) {
        if(success){
            self.focusArray = res;
            [self.tableView reloadData];
        }
    }];
    
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

#pragma mark - 设置导航条
- (void)setUpNavi
{
    [super setUpNavi];
    self.navigationItem.title = @"商品收藏";
}
#pragma mark - 设置tableView
- (void)setUpTableView
{
    UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, ScreenWidth, ScreenHeight) style:UITableViewStyleGrouped];
    tableView.delegate = self;
    tableView.dataSource = self;
    tableView.rowHeight = MineRatio(105);
    [self.view addSubview:tableView];
    self.tableView = tableView;
    
    [self.tableView registerClass:[LXStoreViewCell class] forCellReuseIdentifier:LXStoreViewCellID];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.focusArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    Product * p = self.focusArray[indexPath.row];
    LXStoreViewCell *cell = [tableView dequeueReusableCellWithIdentifier:LXStoreViewCellID];
    [cell.iconImageView sd_setImageWithURL:[NSURL URLWithString:p.thumbnail_pic] placeholderImage:nil];
    cell.nameLabel.text = p.name;
    cell.priceLabel.text = p.price;
    return cell;
}

@end
